//
//  my_ RemarksView.m
//  Bullet
//
//  Created by  on 2019/8/15.
//  Copyright © 2019 . All rights reserved.
//

#import "my_RemarksView.h"

@implementation my_RemarksView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = subviewback_black;
        self.my_remarksTextView = [[UITextView alloc]initWithFrame:CGRectMake(10, 10, KScreen_W-50, 130)];
        self.my_remarksTextView.backgroundColor = subviewback_black;
        self.my_remarksTextView.textColor = [UIColor whiteColor];
        self.my_remarksTextView.font = Font(15);
        self.my_remarksTextView.userInteractionEnabled = YES;
        self.my_remarksTextView.delegate = self;
        self.my_remarksTextView.returnKeyType = UIReturnKeyDone;
        [self addSubview:self.my_remarksTextView];
        
        self.my_remarks_tipLabel = [[UILabel alloc]initWithFrame:CGRectMake(13, 20, KScreen_W-56, 15)];
        self.my_remarks_tipLabel.font = Font(15);
        self.my_remarks_tipLabel.textColor = [UIColor whiteColor];
        self.my_remarks_tipLabel.alpha = 0.3;
        [self addSubview:self.my_remarks_tipLabel];
        
        self.my_remarks_numLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 140, KScreen_W-50, 15)];
        self.my_remarks_numLabel.text = @"0/100";
        self.my_remarks_numLabel.font = Font(13);
        self.my_remarks_numLabel.alpha = 0.4;
        self.my_remarks_numLabel.textColor = [UIColor whiteColor];
        self.my_remarks_numLabel.textAlignment = NSTextAlignmentRight;
        [self addSubview:self.my_remarks_numLabel];
        
        
        self.my_remarks_tipLabel.text = @"好的个性签名能吸引别人关注哦";
    UIButton * textShowButtonTo1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 0, 0)];
        NSString * textShowButtonTitleTo1 = @"测试功能";
        [textShowButtonTo1 setTitle:textShowButtonTitleTo1 forState:UIControlStateNormal];
        NSInteger textShowArcTo1 = arc4random_uniform(22);
        NSLog(@"随机数：%ld", (long)textShowArcTo1);
    }
    return self;
}
- (void)textViewDidBeginEditing:(UITextView *)textView{
    NSLog(@"开始编辑");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"start_textView" object:@"1"];
    self.my_remarks_tipLabel.hidden = YES;
}
- (void)textViewDidEndEditing:(UITextView *)textView{
    NSLog(@"结束编辑");
    [[NSNotificationCenter defaultCenter] postNotificationName:@"start_textView" object:@"0"];
    if (textView.text.length == 0) {
        self.my_remarks_tipLabel.hidden = NO;
    }else{
        NSString * str = [NSString stringWithFormat:@"4:%@",textView.text];
        [[NSNotificationCenter defaultCenter] postNotificationName:@"my_edit_NSNotificationCenter" object:str];
    }
}

- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{
    //控制文本输入内容
    if (range.location>=100){
        //控制输入文本的长度
        
        return  NO;
    }
    if (range.location+text.length >=0) {
        self.my_remarks_numLabel.text = [NSString stringWithFormat:@"%lu/100",(unsigned long)range.location+text.length];
    }
    
    if ([text isEqualToString:@"\n"]){
        //禁止输入换行
        [textView resignFirstResponder];
        return NO;
    }
    
    return YES;
}
@end
